// 导入模块
let mongoose = require('mongoose')
// 连接数据库
mongoose.connect('mongodb://localhost/company',{ useNewUrlParser: true ,useUnifiedTopology: true}).then(()=>{
    console.log('数据库连接成功');
}).catch('数据库连接失败')
// 定义表
let Schema_employees = mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    age:{
        type:Number,
        required:true
    },
    sex:{
        type:String,
        required:true
    },
    department:{
        type:String,
        required:false,
        default:'未知'
    },
    salary:{
        type:String,
        required:false,
        default:'未知'
    }
})

// 创建文档
let Employees = mongoose.model('Employees',Schema_employees)
// 
// Employees.create({
//     name:'周琪',
//     age:20,
//     sex:'女'
// }).then((r)=>{
//     console.log(r);
// })

exports.Employees = Employees
